package com.ws.shop.entity;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.ws.shop.util.StringUtil;



/**
 * 实体类 - 会员
 */

public class Member extends BaseEntity{

	private static final long serialVersionUID = 1533130686714725835L;
	
	public static final String TABLE_NAME = "member";
	
	public static final String LOGIN_MEMBER_ID_KEY = "memberId";// 保存登录会员ID的Session名称
	public static final String LOGIN_MEMBER_NAME_KEY = "memberName";//保存登录会员用户名的session名称
	public static final String LOGIN_MEMBER_REALNAME_KEY = "memberRealname";//保存登录会员真实姓名的session名称
	public static final String LOGIN_MEMBER_BEAT_KEY = "memberBeat";//闪点
	public static final String LOGIN_MEMBER_POINTB_KEY = "memberPointb";//拍点
	public static final String LOGIN_MEMBER_POINTC_KEY = "memberPointc";//积分
	public static final String LOGIN_MEMBER_IP_KEY = "memberIp";//保存访问者IP信息
	public static final String MEBER_ID_FORGET_L = "MEBER_ID_FORGET_L";//保存登陆密码找回对应的会员ID的session名称
	public static final String MEBER_ID_FORGET_S = "MEBER_ID_FORGET_S";//保存二级密码找回对应的会员ID的session名称
	
	public static final int LOGIN_PASSWORD_MIN = 6;
	public static final int LOGIN_PASSWORD_MAX = 20;
	
	public static final int SEC_PWD_MIN = 6;
	public static final int SEC_PWD_MAX = 20;
	
	public static final int PAY_PWD_MIN = 6;
	public static final int PAY_PWD_MAX = 20;
	
	public static final String MAIL_REGEX = "\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+";
	public static final String REAL_NAME_REGEX = "[a-zA-Z\u4e00-\u9fa5]{2,20}$";
	public static final String USER_NAME_REGEX = "[0-9a-z\\-A-Z]{3,20}";
	
	private int id;
	private String name;
	private String mail;
	private String password;
	private String realname;
	private String ip;
	private String head;
	private int sex;
	private Date birthday;
	private String tel;
	private int score;
	private int beat;
	private long pointb;
	private int pointc;
	private int priority;
	private int robot;
	private Date addtime;
	private String phone;
	private int old;
	private int uploadhead;
	private int state;
	private Date acttime;
	
	public final static Map<String,String> STATE_DESCS = new HashMap<String,String>();
	
	static{
		STATE_DESCS.put("0", "未验证");
		STATE_DESCS.put("1", "已验证");
	}
	
	public Member(){}
	
	public Member(int id, String name, String mail, String password,
			String realname, String ip, String head, int sex, Date birthday,
			String tel, int score, int beat, int pointb, int pointc,
			int priority, int robot, Date addtime, String phone, int old,
			int uploadhead, int state) {
		this.id = id;
		this.name = name;
		this.mail = mail;
		this.password = password;
		this.realname = realname;
		this.ip = ip;
		this.head = head;
		this.sex = sex;
		this.birthday = birthday;
		this.tel = tel;
		this.score = score;
		this.beat = beat;
		this.pointb = pointb;
		this.pointc = pointc;
		this.priority = priority;
		this.robot = robot;
		this.addtime = addtime;
		this.phone = phone;
		this.old = old;
		this.uploadhead = uploadhead;
		this.state = state;
	}
	
	public Date getActtime() {
		return acttime;
	}

	public void setActtime(Date acttime) {
		this.acttime = acttime;
	}


	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getMail() {
		return mail;
	}

	public void setMail(String mail) {
		this.mail = mail;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getRealname() {
		return realname;
	}

	public void setRealname(String realname) {
		this.realname = realname;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public String getHead() {
		return head;
	}

	public void setHead(String head) {
		this.head = head;
	}

	public int getSex() {
		return sex;
	}

	public void setSex(int sex) {
		this.sex = sex;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	public int getScore() {
		return score;
	}

	public void setScore(int score) {
		this.score = score;
	}

	public int getBeat() {
		return beat;
	}

	public void setBeat(int beat) {
		this.beat = beat;
	}

	public long getPointb() {
		return pointb;
	}

	public void setPointb(long pointb) {
		this.pointb = pointb;
	}

	public int getPointc() {
		return pointc;
	}

	public void setPointc(int pointc) {
		this.pointc = pointc;
	}

	public int getPriority() {
		return priority;
	}

	public void setPriority(int priority) {
		this.priority = priority;
	}

	public int getRobot() {
		return robot;
	}

	public void setRobot(int robot) {
		this.robot = robot;
	}

	public Date getAddtime() {
		return addtime;
	}

	public void setAddtime(Date addtime) {
		this.addtime = addtime;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public int getOld() {
		return old;
	}

	public void setOld(int old) {
		this.old = old;
	}

	public int getUploadhead() {
		return uploadhead;
	}

	public void setUploadhead(int uploadhead) {
		this.uploadhead = uploadhead;
	}

	public int getState() {
		return state;
	}

	public void setState(int state) {
		this.state = state;
	}

	public static String validUsername(String username,boolean nullable){
		if(StringUtil.isEmpty(username)){
			if(nullable)
				return null;
			else
				return "用户名不能为空";
		}
		if(!username.matches(USER_NAME_REGEX)){
			return "用户名只能为数字、字母或-，且长度在3-20位之间";
		}
		return null;
	}
	
	public static String validRealname(String realname,boolean nullable){
		if(StringUtil.isEmpty(realname)){
			if(nullable)
				return null;
			else
				return "真实姓名不能为空";
		}
		if(!realname.matches(REAL_NAME_REGEX)){
			return "真实姓名只能为字母或汉字，且长度为2-20位";
		}
		return null;
	}
	
	public static String validMail(String email,boolean nullable){
		if(StringUtil.isEmpty(email)){
			if(nullable)
				return null;
			else
				return "邮箱不能为空";
		}
		if(!email.matches(MAIL_REGEX)){
			return "邮件格式错误";
		}
		return null;
	}
	
	public static String validPhone(String phone,boolean nullable){
		if(StringUtil.isEmpty(phone)){
			if(nullable)
				return null;
			else
				return "手机号不能为空";
		}
		if(phone.length() != 11){
			return "手机号码格式错误,长度只能为11为";
		}
		return null;
	}
	
	public static String validPassword(String password,boolean nullable){
		if(StringUtil.isEmpty(password)){
			if(nullable)
				return null;
			else
				return "登陆密码不能为空";
		}
		if(password.length() < LOGIN_PASSWORD_MIN || password.length() > LOGIN_PASSWORD_MAX){
			return "登陆密码长度应为"+LOGIN_PASSWORD_MIN+"-"+LOGIN_PASSWORD_MAX+"位";
		}
		return null;
	}
	

}